<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>滴答办公系统-学员导入</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="media/layui/css/layui.css" media="all">
<script src="media/js/jquery.min.js"></script>
</head>
<body>
	<div class="layui-container" style="margin-top: 5px">
		<form class="layui-form" action="studentbatch.do" method="post" enctype="multipart/form-data">
		<div class="layui-form-item">
				<label class="layui-form-label">下载模板</label>
				<div class="layui-input-block">
					<div class="layui-form-mid layui-word-aux">
						<a href="media/tem/studenttem.xls">批量导入学员模板.xls</a>
					</div>
				</div>
				
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">选择文件</label>
				<div class="layui-input-block">
					<input type="file" name="mFile" id="excel" class="layui-input">
				</div>
			</div>
		    <div class="layui-form-item">
				<input class="layui-btn" style="margin-left: 10%"  id="btn1" onclick="uploadExcel()" value="确认导入">
			</div>
		</form>
	</div>
	<script src="media/layui/layui.js"></script>
	<script>
    function uploadExcel() {
      var excel = $('#excel')[0].files[0];
      
      if(typeof(excel) != "undefined" && excel.name.indexOf(".xls") != -1) {
        var formData = new FormData();
        formData.append("excelFile", excel);
        
        $.ajax({
          url: "/emp/student/uploadExcel",
          type: "POST",
          dataType: "json",
          processData : false, // 使数据不做处理
          contentType : false, // 不要设置Content-Type请求头
          data: formData,
          success: function(data) {
            alert("数据导入成功！");
            window.location.reload();
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
          }
        });
      }else{
        alert("请选择Excel文件！");
      }
    }
  </script>
</body>
</html>